import { useRequest } from 'umi';

import { message } from 'antd';
import { getTenantID, getUserID, requestFunCompon } from '@/utils';

export const useResourRangeTree = () => {
  const requestTree = useRequest(
    () => {
      let reqUrl = `/resourceController/treeGrid`;
      let bodyParams = {
        // positionID: getPosIDs(),
        userID: getUserID(),
        dicTypeIds: `${getTenantID()}0000`,
        pID: null,
        resourceType: null,
      };
      return requestFunCompon('POST', reqUrl, bodyParams);
    },
    {
      onSuccess: (res) => {
        if (!res?.msgFlag) {
          message.error(res?.msg ?? '获取资源菜单失败');
        }
      },
    },
  );

  const reloadTree = () => requestTree.run();

  const treeData = requestTree.data?.obj;

  const treeLoading = requestTree.loading;

  return {
    reloadTree,
    treeData,
    treeLoading,
  };
};
